{extend name="sitehome@style/base"/}
{block name="main"}
<div class="layui-form">
  <div class="layui-form-item">
    <label class="layui-form-label">APP_KEY</label>
    <div class="layui-input-inline">
      <input type="text" name="app_key" lay-verify="app_key" placeholder="请输入app_key"  value="{$list['app_key']}" autocomplete="off" class="layui-input nc-len-long">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">SECRET_KEY</label>
    <div class="layui-input-inline">
      <input type="text" name="secret_key" lay-verify="secret_key" placeholder="请输入secret_key"  value="{$list['secret_key']}" autocomplete="off" class="layui-input nc-len-long">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">短信内容签名</label>
    <div class="layui-input-inline">
      <input type="text" name="signature" lay-verify="signature" placeholder="请输入内容签名"  value="{$list['signature']}" autocomplete="off" class="layui-input nc-len-long">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">启用</label>
    <div class="layui-input-inline">
    	<input type="checkbox" name="status" value="1" lay-skin="switch" lay-filter="switchTest"  {if condition="$status  eq '1'"}checked{/if}>
    </div>
  </div>
  <div class="nc-form-row">
    <button class="layui-btn" lay-submit lay-filter="saveSms">保存</button>
    <a href="javascript:history.back(-1);" class="layui-btn layui-btn-primary">返回</a>
  </div>
</div>

<script>
layui.use('form', function(){
  var form = layui.form;
  form.verify({
  	app_key: function(value){
	    if(value.length == 0){
	      return '请输入APP_KEY';
	    }
	    },
    secret_key: function(value){
	      if(value.length == 0){
	        return '请输入SECRET_KEY';
	      }
	    },
    signature: function(value){
	      if(value.length == 0){
	        return '请输入短信内容签名';
	      }
	    },
	  });
	
  var repeat_flag = false;//防重复标识
  form.on('submit(saveSms)', function(data){
     if(repeat_flag) return;
	  repeat_flag = true;
	  var field = data.field;
       $.ajax({
          type : "post",
          url : '{:addon_url("SmsAliyun://sitehome/Index/config")}',
          dataType : "JSON",
          data : field,
          success : function(res) {
       	  	layer.msg(res.message);
          	if(res.code == 0){
          		location.reload();
            }else{
				repeat_flag = false;
			}
          }
      });
  });
});
</script>
{/block}